package com.zhf.dao.impl;

import com.zhf.dao.UserDao;
import com.zhf.entity.User;
import com.zhf.utils.ConnectionUtil;

import java.util.ArrayList;
import java.util.List;

public class UserDaoImpl implements UserDao {
    @Override
    public User queryUserByUserNameAndPassword(String userName, String password) {
        String sql = "select username,password from user where username = ? and password = ?";
        List<User> users = new ArrayList<>();
        ConnectionUtil.DQL(sql, new Object[]{userName, password}, rs -> {
            try{
                if(rs.next()){
                    User user = new User();
                    String username1 = rs.getString(1);
                    String password1 = rs.getString(2);
                    user.setUsername(username1);
                    user.setPassword(password1);
                    users.add(user);
                }
            }
            catch (Exception e){
                e.printStackTrace();
            }
        });
        if(users != null && users.size() > 0){
            return users.get(0);
        }
        return null;
    }
}
